package com.jeesite.modules.exam.quota.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.exam.quota.entity.DcSupExamQuotaAdd;
import com.jeesite.modules.exam.quota.service.DcSupExamQuotaAddService;

/**
 * 考核任务加减分指标表Controller
 * @author xhc
 * @version 2022-05-28
 */
@Controller
@RequestMapping(value = "${adminPath}/quota/dcSupExamQuotaAdd")
public class DcSupExamQuotaAddController extends BaseController {

	@Autowired
	private DcSupExamQuotaAddService dcSupExamQuotaAddService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupExamQuotaAdd get(String id, boolean isNewRecord) {
		return dcSupExamQuotaAddService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:view")
	@RequestMapping(value = {"list", ""})
	public String list(DcSupExamQuotaAdd dcSupExamQuotaAdd, Model model) {
		model.addAttribute("dcSupExamQuotaAdd", dcSupExamQuotaAdd);
		return "modules/exam/quota/dcSupExamQuotaAddList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupExamQuotaAdd> listData(DcSupExamQuotaAdd dcSupExamQuotaAdd, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamQuotaAdd.setPage(new Page<>(request, response));
		Page<DcSupExamQuotaAdd> page = dcSupExamQuotaAddService.findPage(dcSupExamQuotaAdd);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:view")
	@RequestMapping(value = "form")
	public String form(DcSupExamQuotaAdd dcSupExamQuotaAdd, Model model) {
		model.addAttribute("dcSupExamQuotaAdd", dcSupExamQuotaAdd);
		return "modules/exam/quota/dcSupExamQuotaAddForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupExamQuotaAdd dcSupExamQuotaAdd) {
		dcSupExamQuotaAddService.save(dcSupExamQuotaAdd);
		return renderResult(Global.TRUE, text("保存考核任务加减分指标表成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupExamQuotaAdd dcSupExamQuotaAdd) {
		dcSupExamQuotaAdd.setStatus(DcSupExamQuotaAdd.STATUS_DISABLE);
		dcSupExamQuotaAddService.updateStatus(dcSupExamQuotaAdd);
		return renderResult(Global.TRUE, text("停用考核任务加减分指标表成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupExamQuotaAdd dcSupExamQuotaAdd) {
		dcSupExamQuotaAdd.setStatus(DcSupExamQuotaAdd.STATUS_NORMAL);
		dcSupExamQuotaAddService.updateStatus(dcSupExamQuotaAdd);
		return renderResult(Global.TRUE, text("启用考核任务加减分指标表成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaAdd:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupExamQuotaAdd dcSupExamQuotaAdd) {
		dcSupExamQuotaAddService.delete(dcSupExamQuotaAdd);
		return renderResult(Global.TRUE, text("删除考核任务加减分指标表成功！"));
	}
	
}